package com.javasm.crm.service.impl.productimpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javasm.crm.domin.criteria.CheckCriteria;
import com.javasm.crm.domin.criteria.ProductCriteria;
import com.javasm.crm.domin.entity.productEntity.PriceCheckVo;
import com.javasm.crm.domin.entity.productEntity.ProductInfo;
import com.javasm.crm.domin.entity.productEntity.ProductVo;
import com.javasm.crm.mapper.goodsmapper.PriceCheckVoMapper;
import com.javasm.crm.mapper.goodsmapper.ProductVoMapper;
import com.javasm.crm.service.productservice.PriceCheckVoService;
import com.javasm.crm.service.productservice.ProductVoService;
import com.javasm.crm.utils.page.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.List;

/**
 * @Author：zhangyang
 * @Version：1.0
 * @Date：2021/7/12-17:00
 * @desp:
 * @since:
 */
@Service
@Transactional
public class PriceCheckVoServiceImpl extends ServiceImpl<PriceCheckVoMapper, PriceCheckVo> implements PriceCheckVoService {
    @Autowired
    PriceCheckVoMapper priceCheckVoMapper;

    @Override
    public PageResult<PriceCheckVo> searchPageByCriteria(CheckCriteria checkCriteria) {
        Integer currentPage = checkCriteria.getCurrentPage();
        Integer pageSize = checkCriteria.getPageSize();
        if (StringUtils.isEmpty(currentPage)) {
            currentPage=1;
        }
        if (StringUtils.isEmpty(pageSize)) {
            pageSize=5;
        }
        QueryWrapper<PriceCheckVo> exampleQueryWrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(checkCriteria.getCheckId())){
            exampleQueryWrapper.eq("gc.check_id",checkCriteria.getCheckId());
        }
        if (!StringUtils.isEmpty(checkCriteria.getGoodName())) {
            exampleQueryWrapper.like("gi.good_name", checkCriteria.getGoodName());
        }
        Page<PriceCheckVo> examplePage = new Page<>(currentPage, pageSize);
        List<PriceCheckVo> queryall = priceCheckVoMapper.queryall(examplePage, exampleQueryWrapper);

        return new PageResult<PriceCheckVo>(examplePage.getTotal(), queryall);
    }
}
